# 导入:
from sqlalchemy import Column, String, create_engine, BIGINT, Integer
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from domain.domain import Plant as Catalog
from dao.PlantDAO import PlantDAO as  CatalogDAO
from helper.ConnectionHelper import ConnectionHelper


# mysqlconnector
DB_CONNECT_STRING =ConnectionHelper.GetConnectionURL()
engine = create_engine(DB_CONNECT_STRING, echo=True)

# 初始化数据库连接:
# engine = create_engine('mysql+mysqlconnector://root:root@localhost:3306/ctbu')
# 创建DBSession类型:
DBSession = sessionmaker(bind=engine)

# 创建Session:
session = DBSession()

catalogDao = CatalogDAO()
catalog = catalogDao.getById(session, 1)
print(catalog.name)
catalogDao1=catalogDao.add(session,newCatalog)
#catalogDao.update(session,catalog)


# 创建Query查询，filter是where条件，最后调用one()返回唯一行，如果调用all()则返回所有行:

# 打印类型和对象的name属性:
print('type:', type(catalog))
print('name:', catalog.name)
# 关闭Session:
session.close()
